package com.wave.blog.serve.enums;

import com.mybatisflex.annotation.EnumValue;
import lombok.Getter;

/**
 * 文章状态枚举
 *
 * @author wave
 */
@Getter
public enum ArticleStatusEnum {
    /**
     * 草稿
     */
    DRAFT(0, "草稿"),
    
    /**
     * 已发布
     */
    PUBLISHED(1, "已发布");
    
    @EnumValue
    private final Integer code;
    
    private final String desc;
    
    ArticleStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }
    
    /**
     * 根据code获取枚举
     *
     * @param code 状态码
     * @return 枚举对象
     */
    public static ArticleStatusEnum getByCode(Integer code) {
        for (ArticleStatusEnum status : values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        return null;
    }
}